package com.bbs.publish;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

//创建事件发布者(抽象)
//底层调用applicationEventPublisher进行发布
//这个bean是我们调用底层applicationEventPublisher发布事件的媒介
@Component
public class EventPublisher implements ApplicationEventPublisherAware {

    ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher=applicationEventPublisher;
    }
    //发布事件
    public void sendEvent(ApplicationEvent applicationEvent){
        applicationEventPublisher.publishEvent(applicationEvent);
    }

}
